/**
 *  @(#)  IFAAAuthenticator  module    1.0  2017/03/24
 *
 *  Copyright  (c)  2017,  IFAA  and/or  its  affiliates.  All  rights  reserved.
 *
 *  Redistribution  and  use  in  source  and  binary  forms,  with  or  without
 *  modification,  are  permitted  provided  that  the  following  conditions  are  met:
 *
 *  -Redistribution  of  source  code  must  retain  the  above  copyright  notice,  this
 *    list  of  conditions  and  the  following  disclaimer.
 *
 *  -Redistribution  in  binary  form  must  reproduce  the  above  copyright  notice,
 *    this  list  of  conditions  and  the  following  disclaimer  in  the  documentation
 *    and/or  other  materials  provided  with  the  distribution.
 *
 *  Neither  the  name  of  IFAA  or  the  names  of  contributors  may
 *  be  used  to  endorse  or  promote  products  derived  from  this  software  without
 *  specific  prior  written  permission.
 *
 *  This  software  is  provided  "AS  IS,"  without  a  warranty  of  any  kind.  ALL
 *  EXPRESS  OR  IMPLIED  CONDITIONS,  REPRESENTATIONS  AND  WARRANTIES,  INCLUDING
 *  ANY  IMPLIED  WARRANTY  OF  MERCHANTABILITY,  FITNESS  FOR  A  PARTICULAR  PURPOSE
 *  OR  NON-INFRINGEMENT,  ARE  HEREBY  EXCLUDED.  IFAA,  ORG.
 *  AND  ITS  LICENSORS  SHALL  NOT  BE  LIABLE  FOR  ANY  DAMAGES  SUFFERED  BY  LICENSEE
 *  AS  A  RESULT  OF  USING,  MODIFYING  OR  DISTRIBUTING  THIS  SOFTWARE  OR  ITS
 *  DERIVATIVES.  IN  NO  EVENT  WILL  IFAA  OR  ITS  LICENSORS  BE  LIABLE  FOR  ANY  LOST
 *  REVENUE,  PROFIT  OR  DATA,  OR  FOR  DIRECT,  INDIRECT,  SPECIAL,  CONSEQUENTIAL,
 *  INCIDENTAL  OR  PUNITIVE  DAMAGES,  HOWEVER  CAUSED  AND  REGARDLESS  OF  THE  THEORY
 *  OF  LIABILITY,  ARISING  OUT  OF  THE  USE  OF  OR  INABILITY  TO  USE  THIS  SOFTWARE,
 *  EVEN  IF  IFAA  HAS  BEEN  ADVISED  OF  THE  POSSIBILITY  OF  SUCH  DAMAGES.
 *
 *  You  acknowledge  that  this  software  is  not  designed,  licensed  or  intended
 *  for  use  in  the  design,  construction,  operation  or  maintenance  of  any
 *  nuclear  facility.
 *
 */
package com.ifaa.sdk.api;

/**
 * BIC数据模型
 * @author qiyi.wxc
 */
public class BICDataModel {

    /**
     * 客户端的开通状态, 0为未开通, 2为开通
     */
    private int             clientStatus;

    /**
     * 业务类型：<br>1、指纹支付
     */
    private int             authType;

    /**
     * 可穿戴设备类型：<br>1
     */
    private int             wearableType;

    /**
     * 协议类型：2 通用方案
     */
    private int             protocalType;

    /**
     * 协议的版本，目前为1
     */
    private int             protocalVersion;

    /**
     * 设备的制造商类型
     */
    private int             vendor;

    /**
     * 客户端Service版本，替换为移动收银台版本
     */
    private int             serviceVersion;

    /**
     * 设备ID
     */
    private String          deviceId;

    /**
     * 用户手机的型号
     */
    private String          phoneModel;

    /**
     * device model (aaid)
     */
    private String          deviceModel;

    /**
     * 认证参数
     */
    private String          authParameter;

    /**
     * 格式定义<pre>
    *      ai:clientStatus#authType#wearableType#protocalType#protocalVersion#vender#serviceVersion</pre>
     */
    public BICDataModel(String authInfo, String deviceId, String authParameter, String phoneModel, String deviceModel) {
        String[] authInfoList = authInfo.split("#");
        if (authInfoList.length < 6) {
            return;
        }

        this.clientStatus = Integer.parseInt(authInfoList[0]);
        this.authType = Integer.parseInt(authInfoList[1]);
        this.wearableType = Integer.parseInt(authInfoList[2]);
        this.protocalType = Integer.parseInt(authInfoList[3]);
        this.protocalVersion = Integer.parseInt(authInfoList[4]);
        this.vendor = Integer.parseInt(authInfoList[5]);

        if (authInfoList.length >= 7) {
            this.serviceVersion = Integer.parseInt(authInfoList[6]);
        } else {
            this.serviceVersion = 100;
        }

        this.deviceId = deviceId;
        this.phoneModel = phoneModel;
        this.authParameter = authParameter;
        this.deviceModel = deviceModel;
    }

    public BICDataModel(int clientStatus, int authType, int wearableType, int protocalType,
                        int protocalVersion, int vendor, int serviceVersion, String deviceId,
                        String phoneModel, String deviceModel) {
        this.clientStatus = clientStatus;
        this.authType = authType;
        this.wearableType = wearableType;
        this.protocalType = protocalType;
        this.protocalVersion = protocalVersion;
        this.vendor = vendor;
        this.serviceVersion = serviceVersion;
        this.deviceId = deviceId;
        this.phoneModel = phoneModel;
        this.deviceModel = deviceModel;
        this.authParameter = "";
    }

    public int getClientStatus() {
        return clientStatus;
    }

    public int getAuthType() {
        return authType;
    }

    public int getWearableType() {
        return wearableType;
    }

    public int getProtocalType() {
        return protocalType;
    }

    public int getProtocalVersion() {
        return protocalVersion;
    }

    public int getVendor() {
        return vendor;
    }

    public int getServiceVersion() {
        return serviceVersion;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public String getPhoneModel() {
        return phoneModel;
    }

    public String getDeviceModel() {
        return deviceModel;
    }

    public String getAuthParameter() {
        return authParameter;
    }

    /**
     * 获取封装的AuthInfo
     * clientStatus#authType#wearableType#protocalType#protocalVersion#vender#serviceVersion
     */
    final String getAuthInfo() {
        return clientStatus + "#" + authType + "#" + wearableType + "#" + protocalType + "#"
               + protocalVersion + "#" + vendor + "#" + serviceVersion;
    }
}
